<template>
  <div class="content-layout">
    <div class="headLayout">
      <img class="headBg" src="@/assets/image/money.jpg">
      <div class="headBottom"></div>
      <div class="head_user">
        <div class="head_user_img">
          <HeadImage :type="1"></HeadImage>
        </div>
        <div class="userinfo">
          <span class="text_name">{{userData.agentName}}</span>
          <IdentityTag :type="userData.agentLevel"></IdentityTag>
        </div>
        <span class="date_desc">注册人数</span>
        <div class="statisticals">
          <div class="statisticals-item">
            <p class="statisticals-num">{{probably.todatTotali}}</p>
            <p class="statisticals-txt">今日</p>
          </div>
          <div class="statisticals-item bl">
            <p class="statisticals-num">{{probably.yesterdayTotali}}</p>
            <p class="statisticals-txt">昨日</p>
          </div>
          <div class="statisticals-item bl">
            <p class="statisticals-num">{{probably.thisWeekTotali}}</p>
            <p class="statisticals-txt">本周</p>
          </div>
          <div class="statisticals-item bl">
            <p class="statisticals-num">{{probably.thisWeekTotali}}</p>
            <p class="statisticals-txt">本月</p>
          </div>
        </div>
        <img class="setting" src="@/assets/image/setting2.png" v-on:click="$router.push({path:'/setting'})">
      </div>
    </div>
    <div class="meunlayout" v-if="userData.agentLevel!=null">
      <div class="meunTitleLayout">
        <p class="meunTitle">代理商服务</p>
      </div>
      <div v-for="(item1,index1) in meunList" class="mitems">
        <div v-for="(item2,index2) in item1" :class="{mitem:true,right_line:index2 < item1.length,bottom_line:true} "
             v-on:click="onMeunClick(item2)">
          <img v-bind:src="item2.icon" :class="{micon:true,hidden:isShowMeun(item2.id,userData.agentLevel)}">
          <p :class="{mtext:true,hidden:isShowMeun(item2.id,userData.agentLevel)}">{{item2.label}}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import HeadImage from '@/components/HeadImage/index'
  import icon_adduser from '@/assets/image/icon_adduser.png'
  import icon_agent from '@/assets/image/icon_agent.png'
  import icon_shouyi from '@/assets/image/icon_shouyi.png'
  import icon_tongji from '@/assets/image/icon_tongji.png'
  import icon_tuiguang from '@/assets/image/icon_tuiguang.png'
  import IdentityTag from '@/components/IdentityTag/index'
  import {loginInfo, userProbably} from "@/api/user";
  import {Dialog} from 'vant';


  export default {
    name: "home",
    components: {HeadImage, IdentityTag},
    data() {
      return {
        meunList: [
          [
            {
              id: 1,
              label: "注册统计",
              path: "/userReg",
              icon: icon_tongji,
            },
            {
              id: 2,
              label: "收益统计",
              path: "/earnings",
              icon: icon_shouyi,
            },
            {
              id: 3,
              label: "推广",
              path: "http://m.juyuanapp.com/promotion",
              icon: icon_tuiguang,
            }
          ],
          [
            {
              id: 4,
              label: "我的代理商",
              path: "/agentList",
              icon: icon_agent,
            },
            {
              id: 5,
              label: "开通代理商",
              path: "/agentAdd",
              icon: icon_adduser,
            },
            {}
          ]
        ],
        probably: {
          todatTotali: 0,
          yesterdayTotali: 0,
          thisWeekTotali: 0,
          thisWeekTotali: 0
        },
        userData: {
          inviteCode: null,
          agentName: "-",
          agentLevel: null
        }
      }
    },
    mounted() {
      this.init();
    },
    methods: {
      init() {
        let _this = this;
        loginInfo().then(response => {
          _this.userData = response.data;

        })
        userProbably().then(response => {
          _this.probably = response.data;
        })
      },
      onMeunClick(item) {
        if (this.isShowMeun(item.id, this.userData.agentLevel)) return
        if (item.id == 3) {
          if (this.userData.inviteCode == null) {
            Dialog.alert({
              title: '系统提示',
              message: '请刷新页面',
            });
            return;
          }
          window.open(item.path + '/' + this.userData.inviteCode, "_blank");
        } else {
          this.$router.push(item.path)
        }
        return;
      },
      isShowMeun(id, agentLevel) {
        return id == null || (agentLevel == 4 && (id == 4 || id == 5));
      }
    }
  }
</script>
<style lang="scss" scoped>
  @import './index.scss';
</style>
